import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
#%matplotlib inline
#taking a dataset asylum_seekers_monthly.csv
ASM=pd.read_csv('C:\\Users\\Dell\\OneDrive\\Desktop\\PROJECTS\\DV\\asylum_seekers_monthly.csv')
ASM
ASM.head()
df = pd.DataFrame(ASM)
df['Value'] = pd.to_numeric(df['Value'],errors='coerce')
df = df.replace(np.nan, 0, regex=True)
df['Value'] = df['Value'].astype(int)
print (df)
print (df.dtypes)
origin_plot= df.Origin.value_counts().plot(kind="bar",x=data["Origin"],title="Countries from which most people migrate",legend=True)
fig = origin_plot.get_figure()
plt.figure(figsize=(750,300))
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
ASM=pd.read_csv("C:\\Users\\Dell\\OneDrive\\Desktop\\PROJECTS\\DV\\asylum_seekers_monthly.csv")
fig=plt.figure()
ax=fig.add_axes([0,0,1,1])
x=ASM["Origin"]
x=list(dict.fromkeys(x))
y=ASM.Origin.value_counts()
print(y)
y.plot(kind="bar",x=ASM["Origin"],legend="True")
ax.set_title("Countries from which most people migrate",fontsize="20")
fig.set_size_inches(15,10)
plt.savefig("C:\\Users\\Dell\\OneDrive\\Desktop\\PROJECTS\\DV\\graphs\\1.jpg")
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
ASM=pd.read_csv("C:\\Users\\Dell\\OneDrive\\Desktop\\PROJECTS\\DV\\asylum_seekers_monthly.csv")
fig=plt.figure()
ax=fig.add_axes([0,0,1,1])
x=ASM["territory_of_asylum"]
x=list(dict.fromkeys(x))
y=ASM.territory_of_asylum.value_counts()
print(y)
y.plot(kind="bar",x=ASM["territory_of_asylum"],legend="True")
ax.set_title("Countries to which most people migrate",fontsize="20")
fig.set_size_inches(15,10)
plt.savefig("C:\\Users\\Dell\\OneDrive\\Desktop\\PROJECTS\\DV\\graphs\\2.jpg")
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
data=pd.read_csv("C:\\Users\\Dell\\OneDrive\\Desktop\\PROJECTS\\DV\\asylum_seekers_monthly.csv")
y=data.Origin.value_counts()
val=[]
sta=[]
fig = plt.figure()
ax = fig.add_axes([0,0,1,1])
for x in range(0,len(y),1):
if(y[x]>=30):
val.append(y[x])
key=y.keys()
for i in range(0,len(val),1):
sta.append(key[i])
ax.pie(val,labels=sta,autopct='%1.2f%%')
fig.set_size_inches(18.5, 10.5)
plt.savefig("C:\\Users\\Dell\\OneDrive\\Desktop\\PROJECTS\\DV\\graphs\\3.jpg")
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
data=pd.read_csv("C:\\Users\\Dell\\OneDrive\\Desktop\\PROJECTS\\DV\\asylum_seekers_monthly.csv")
y=data.territory_of_asylum.value_counts()
val=[]
sta=[]
fig = plt.figure()
ax = fig.add_axes([0,0,1,1])
for x in range(0,len(y),1):
if(y[x]>=30):
val.append(y[x])
key=y.keys()
for i in range(0,len(val),1):
sta.append(key[i])
ax.pie(val,labels=sta,autopct='%1.2f%%')
fig.set_size_inches(18.5, 10.5)
plt.savefig("C:\\Users\\Dell\\OneDrive\\Desktop\\PROJECTS\\DV\\graphs\\4.jpg")
print (ASM.dtypes)
df = pd.DataFrame(ASM)
df['Value'] = pd.to_numeric(df['Value'],errors='coerce')
df = df.replace(np.nan, 0, regex=True)
df['Value'] = df['Value'].astype(int)
print (df)
print (df.dtypes)
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
ASM=pd.read_csv("C:\\Users\\Dell\\OneDrive\\Desktop\\PROJECTS\\DV\\asylum_seekers_monthly.csv")
df = pd.DataFrame(ASM)
df['Value'] = pd.to_numeric(df['Value'],errors='coerce')
df = df.replace(np.nan, 0, regex=True)
df['Value'] = df['Value'].astype(int)
fig = plt.figure()
ax = fig.add_axes([0,0,1,1])
x=df["Year"]
y=df["Value"]
ax.set_xlabel("Year",fontsize="20")
ax.set_ylabel("Value",fontsize="20")
ax.set_title("Immigrants accordind to year between 1999 to 2016",fontsize="20" )
ax.scatter(x,y)
fig.set_size_inches(15,10)
plt.savefig("C:\\Users\\Dell\\OneDrive\\Desktop\\PROJECTS\\DV\\graphs\\5.jpg")
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
df = pd.read_csv("C:\\Users\\Dell\\OneDrive\\Desktop\\PROJECTS\\DV\\asylum_seekers_monthly.csv")
df.isna().sum()
df[df.Value == '*']
df = df[df.Value != '*']
#since value is in object so converting it into int
#df['Value'].astype(str)
df['Value'] = pd.to_numeric(df['Value'])
df.info()
# Heatmap visualization
grouped_df = df.groupby(['territory_of_asylum','Origin'])['Year'].count().reset_index()
grouped_df = grouped_df.pivot('territory_of_asylum', 'Origin', 'Year')
grouped_df.head()
plt.figure(figsize=(20,20))
sns.heatmap(grouped_df,cmap="YlGnBu")
plt.title("Heatmap showing territory_of_asylum vs Origin in yearwise")
plt.show()
pd.crosstab(df["territory_of_asylum"]=="Australia",df["Origin"]=='Afghanistan')
## since the above is not much clear. so lets do by each country .i.e seeing the heatmap of each territory_of_asylum vs all Origin
grouped_df = df.groupby(['territory_of_asylum','Origin'])['Year'].count().reset_index()
grouped_df.head()
def country(x):
grouped_df1 =grouped_df[grouped_df['territory_of_asylum']==x]
grouped_df1 = grouped_df1.pivot(index='territory_of_asylum',columns= 'Origin',values= 'Year')
return grouped_df1
tmo=df['territory_of_asylum'].value_counts()
tmo.index
for con in tmo.index:
grouped_df1 = country(con)
plt.figure(figsize=(20,5))
sns.heatmap(grouped_df1,cmap="YlGnBu")
plt.title(f"Heatmap showing {con} vs Origin in yearwise")
plt.show()
## now lets do the same but with respect to total refugee count
grouped_df = df.groupby(['territory_of_asylum','Origin'])['Value'].sum().reset_index()
grouped_df.head()
def country(x):
grouped_df1 =grouped_df[grouped_df['territory_of_asylum']==x]
grouped_df1 = grouped_df1.pivot(index='territory_of_asylum',columns= 'Origin',values= 'Value')
return grouped_df1
grouped_df1 =grouped_df[grouped_df['territory_of_asylum']=='Afghanistan']
grouped_df1 = grouped_df1.pivot(index='territory_of_asylum',columns= 'Origin',values= 'Value')
for con in tmo.index:
grouped_df1 = country(con)
plt.figure(figsize=(20,5))
sns.heatmap(grouped_df1,cmap="YlGnBu")
plt.title(f"Heatmap showing {con} vs Origin in yearwise")
plt.show()